package tech.xs.common.framework.init.db.domain.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

public enum Model {

    /**
     * 忽略插入,如果数据已经存在,则忽略
     */
    IGNORE_INSERT("ignoreInsert");

    @Getter
    @JsonValue
    private final String code;

    private static final Map<String, Model> mappings = new HashMap<>(Model.values().length);

    static {
        for (Model item : values()) {
            mappings.put(item.getCode(), item);
        }
    }

    Model(String code) {
        this.code = code;
    }

    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
    public Model create(String code) {
        return mappings.get(code);
    }

}
